#!/bin/bash
downl_url='https://gitee.com/RuoliCloud/django/raw/master'
function ChangeYUM() {
    #更换YUM源
    wget $downl_url/yumcd.sh -O yumcd.sh
    sh yumcd.sh -A
}
function Installrequirements() {
    #安装python3 unzip mysql
    yum -y install python3 unzip mariadb-server mariadb curl
    # 更换pip默认源
    mkdir ~/.pip
    wget $downl_url/pip.conf -O ~/.pip/pip.conf
    #安装django等
    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ django requests setuptools wheel sqlparse djangorestframework
}
function Getfiles() {
    #将打包的django包上传到服务器里
    mkdir /home/$name
    cd ../home/$name
    wget $downl_url/$name.zip -O $name.zip
    unzip $name.zip
}
function startProject() {
    #进入项目文件夹
    cd /home/$name
    python3 manage.py runserver 0.0.0.0:8888
}
function First () {
    echo -e "开始前请将项目ALLOWED_HOSTS和APP等配置完成再打包上传到服务器里"
    echo -e "\t项目压缩包为project.zip\t"
    read -p "请输入项目名称" name
    ChangeYUM
    Installrequiremnts
    Getfiles
    startProject
}
First
